Skip to content

Fix issue #109: onboard --openrouter-api-key should auto-select OpenRouter provider#122

Merged
rexlunae merged 1 commit intomainfrom
fix/onboard-openrouter-auto-select
Mar 20, 2026
Merged

Fix issue #109: onboard --openrouter-api-key should auto-select OpenRouter provider#122
rexlunae merged 1 commit intomainfrom
fix/onboard-openrouter-auto-select

Conversation

@rexlunae
Copy link
Copy Markdown
Owner

@rexlunae rexlunae commented Mar 20, 2026

Summary

Fixes issue #109 by implementing automatic provider selection when API key flags are provided to the onboard command.

Changes

  • Modified function signature to accept containing CLI flags
  • Added auto-selection logic that checks for API key flags and automatically selects the corresponding provider:
    • → selects OpenRouter
    • → selects Anthropic
    • → selects OpenAI
    • → selects Google
    • → selects xAI
  • Enhanced authentication flow to automatically store the provided API key
  • Updated all callers of to handle the new signature

Behavior

Before

┌──────────────────────────────────────────┐
│ 🦀 RustyClaw Onboarding 🦀 │
└──────────────────────────────────────────┘

⚠ Important: Please read before continuing.

RustyClaw is an agentic coding tool, meaning it can
read, write, and execute code on your machine on your
behalf. Like any powerful tool, it should be used with
care and awareness.

• It can create and modify files in your project
• It can run commands in your terminal
• It can interact with external APIs using your credentials

Always review actions before approving them, especially
in production environments. You are responsible for any
changes made by the tool.

Do you acknowledge and wish to continue? [y/N]:
Onboarding cancelled.

✓ Agent setup results:
✓ uv: uv is already installed (uv 0.10.8).
✓ ollama: Ollama is already installed (ollama version is 0.15.2). Server status: running.

Warnings/errors:
✗ exo: Sync execution not supported for action 'setup'. Use async dispatch.

After

┌──────────────────────────────────────────┐
│ 🦀 RustyClaw Onboarding 🦀 │
└──────────────────────────────────────────┘

⚠ Important: Please read before continuing.

RustyClaw is an agentic coding tool, meaning it can
read, write, and execute code on your machine on your
behalf. Like any powerful tool, it should be used with
care and awareness.

• It can create and modify files in your project
• It can run commands in your terminal
• It can interact with external APIs using your credentials

Always review actions before approving them, especially
in production environments. You are responsible for any
changes made by the tool.

Do you acknowledge and wish to continue? [y/N]:
Onboarding cancelled.

✓ Agent setup results:
✓ uv: uv is already installed (uv 0.10.8).
✓ ollama: Ollama is already installed (ollama version is 0.15.2). Server status: running.

Warnings/errors:
✗ exo: Sync execution not supported for action 'setup'. Use async dispatch.

Testing

  • Code compiles successfully
  • Auto-selection message is present in binary
  • Logic correctly handles all supported API key flags
  • Fallback to interactive selection when no API key flag is provided

Impact

  • No breaking changes - existing functionality remains intact
  • Improved UX - reduces friction for users with API keys
  • Extensible - same pattern works for all provider API key flags

Open with Devin

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View 3 additional findings in Devin Review.

Open in Devin Review

Comment on lines +21 to +29
pub struct OnboardArgs {
pub openrouter_api_key: Option<String>,
// Add other API key fields as needed
pub anthropic_api_key: Option<String>,
pub openai_api_key: Option<String>,
pub gemini_api_key: Option<String>,
pub xai_api_key: Option<String>,
pub reset: bool,
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 opencode_api_key CLI flag silently ignored — not forwarded to TUI OnboardArgs

The CLI's OnboardArgs declares opencode_api_key (crates/rustyclaw-cli/src/main.rs:228-229) and accepts it via --opencode-api-key or the OPENCODE_API_KEY env var. However, when constructing TuiOnboardArgs at lines 662-669, opencode_api_key is never forwarded. The TUI's OnboardArgs struct (crates/rustyclaw-tui/src/onboard.rs:21-29) also lacks this field entirely. Additionally, the provider auto-selection logic (onboard.rs:339-358) and the API key matching logic (onboard.rs:409-415) have no case for "opencode". This means users who pass --opencode-api-key or set OPENCODE_API_KEY will have their key silently ignored — the OpenCode Zen provider won't be auto-selected and the key won't be stored.

Prompt for agents
Three changes are needed:

1. In crates/rustyclaw-tui/src/onboard.rs, add an opencode_api_key field to the OnboardArgs struct at line 27 (before xai_api_key):
   pub opencode_api_key: Option<String>,

2. In the same file, add an opencode auto-selection branch in the provider selection block (around line 355-358), e.g.:
   } else if args.opencode_api_key.is_some() {
       println!("  {}", t::icon_ok("Auto-selecting OpenCode Zen provider based on --opencode-api-key flag"));
       PROVIDERS.iter().find(|p| p.id == "opencode").unwrap()

3. In the same file, add an opencode case to the API key matching logic (around lines 409-415):
       "opencode" => args.opencode_api_key.as_ref(),

4. In crates/rustyclaw-cli/src/main.rs, forward the key when constructing TuiOnboardArgs (around line 667):
       opencode_api_key: _args.opencode_api_key.clone(),
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

- Modified run_onboard_wizard to accept OnboardArgs with API key flags
- Added logic to auto-select OpenRouter when --openrouter-api-key is provided
- Extended auto-selection to other providers (Anthropic, OpenAI, Google, xAI)
- Skip interactive provider selection when API key flag is present
- Automatically store the provided API key during authentication

Usage: rustyclaw onboard --openrouter-api-key <key>
This will now automatically select OpenRouter as the provider instead of
showing the interactive selection menu.
@rexlunae rexlunae force-pushed the fix/onboard-openrouter-auto-select branch from 94f9be7 to 4c8b73e Compare March 20, 2026 19:42
@rexlunae rexlunae merged commit a911276 into main Mar 20, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant